package database.example.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class CloserUtil {
	public static void close(Connection conn){
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				System.err.println(e);
			}finally{
				conn=null;
				System.out.println("MySQL Connection closed!!");
			}
		}
	}
	
	public static void close(PreparedStatement pstmt){
		try {
			pstmt.close();
		} catch (SQLException e) {
			System.err.println(e);
		}finally{
			pstmt=null;
		}
	}
	
	public static void close(PreparedStatement pstmt, Connection conn){
		close(pstmt);
		close(conn);		
	}

	public static void close(ResultSet rs, PreparedStatement pstmt,
			Connection conn) {

		close(rs);
		close(pstmt, conn);
	}

	public static void close(ResultSet rs) {
		try {
			rs.close();
		} catch (SQLException e) {
			System.err.println(e);
		}finally{
			rs=null;
		}		
	}
}
